package com.learn.spring.observer.service.impl;

import com.learn.spring.observer.message.PlaceOrderMessage;
import com.learn.spring.observer.order.*;
import com.learn.spring.observer.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

/**
 * 订单实现类-被观察者实现类
 *
 * @author cong zhi
 * @email 448341911@qq.com
 * @createDate 2023/3/20 16:49
 * @version: v1.0
 */
@Service
@Slf4j
public class OrderServiceImpl extends OrderSubject implements OrderService {

    @Override
    public PlaceOrderResVO placeOrder(PlaceOrderReqVO reqVO) {
        log.info("[placeOrder] start.");
        PlaceOrderResVO resVO = new PlaceOrderResVO();
        // 添加观察者
        this.addObserver(new OrderMetricsObserver());
        this.addObserver(new OrderLogObserver());
        this.addObserver(new OrderNotifyObServer());
        // 通知观察者
        this.notifyObserver(new PlaceOrderMessage());
        log.info("[placeOrder] end.");
        return resVO;
    }
}
